package com.snailct.bpp.router.factory;

import com.snailct.bpp.commons.exception.ErrorCode;
import com.snailct.bpp.router.IServiceHandler;
import com.snailct.bpp.router.request.RemoteServiceHandler;
import com.snailct.bpp.router.RouterException;
import com.snailct.bpp.service.core.definition.ServiceDefinition;
import com.snailct.bpp.service.core.definition.ServiceType;

/**
 * 客户端使用工厂，用于实例化相应的调用器，
 *
 */
public class ServiceFactory {
    private enum ServiceFactoryError{
        @ErrorCode(comment = "Invoker service fail,Unable to sendViaPost to url ${1}service impl!")
        INVLKE_SERIVCE_ERROR
    }
    public static IServiceHandler getServiceHandlerInstance(ServiceDefinition definition){
        if(definition==null||definition.getServiceType()==null){
            throw new RouterException(ServiceFactoryError.INVLKE_SERIVCE_ERROR);
        }
        if(definition.getServiceType().equals(ServiceType.WS)||definition.getServiceType().equals(ServiceType.HTTP)){
            return new RemoteServiceHandler();
        }
        return null;
    }

}
